<%@page import="com.glowdayz.glowmee.dao.EventCommentDAO"%>
<%@page import="com.glowdayz.glowmee.cmd.EventCommentCMD"%>
<%@ page language="java" contentType="text/xml; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@page import="com.glowdayz.common.DBHandler"%>
<%@page import="com.glowdayz.common.ApiHandler"%>
<%@page import="com.glowdayz.common.ApiHandler.XmlData"%>
<%@page import="java.util.ArrayList"%>
<%
	DBHandler.getInstance().connect();

	ApiHandler web = new ApiHandler(request, out, "JSPglowmee");
	
	int rId = web.getInt("rId");
	int bId = web.getInt("bId");
	String comment = web.getValue("comment");
	
	int insert = 0;
	
	int commentCount = DBHandler.getInstance().getCount("eventcomment", "*", "idRegister=" + rId + " AND idAdminBoard=" + bId);
	if (commentCount > 0) {
		DBHandler.getInstance().disconnect();
		web.result(null, "이미 이벤트 댓글이 등록되었습니다.");
		return;
	}
	
	EventCommentCMD cmd = new EventCommentCMD(rId, bId, comment);
	insert = EventCommentDAO.getInstance().insertEventComment(cmd);
	
	if (insert < 1) {
		DBHandler.getInstance().disconnect();
		web.result(null, "등록에 실패하였습니다.");
		return;
	}
	
	DBHandler.getInstance().disconnect();
	
	ArrayList<XmlData> list = new ArrayList<XmlData>();
	list.add(new XmlData("seq", insert));
	web.result("SUCCESS", "댓글이 등록되었습니다.", list);
%>